package com.koko.service.Impl;

import com.koko.constant.MessageConstant;
import com.koko.context.BaseContext;
import com.koko.exception.WishlistAlreadyExistException;
import com.koko.mapper.WishlistMapper;
import com.koko.service.WishlistService;
import com.koko.user.entity.Wishlist;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WishlistServiceImpl implements WishlistService {
    @Autowired
    private WishlistMapper wishlistMapper;
    @Override
    public void addGameToWishlist(Long gameId) {
        Wishlist wishlist = Wishlist.builder().userId(BaseContext.getCurrentId()).gameId(gameId).build();
        Integer count = wishlistMapper.checkIfExists(wishlist);
        if (count > 0) {
            throw new WishlistAlreadyExistException(MessageConstant.WISHLIST_ALREADY_EXIST);
        }
        wishlistMapper.insert(wishlist);
    }
}
